home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / showinfo.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  169 lines

  1. ;$Id: showinfo.pro,v 1.8 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5.  
  6. PRO ShowInfoEventHndlr, event
  7.  
  8.    WIDGET_CONTROL, GET_UVALUE = state, event.top, /NO_COPY
  9.  
  10.    CASE event.id OF
  11.  
  12.       state.wInfoWindow: BEGIN
  13.  
  14.            ; Get the new size of the window
  15.          WIDGET_CONTROL, state.wInfoWindow, TLB_GET_SIZE=windowSize
  16.          
  17.            ; Determine the change in the window size
  18.          deltaX = windowSize[0] - state.windowSize[0]
  19.          deltaY = windowSize[1] - state.windowSize[1]
  20.  
  21.            ; Store the new size in the state structure for later comparisons
  22.          state.windowSize = windowSize
  23.  
  24.            ; Get the pixel size of the text widget
  25.          textEditGeometry = WIDGET_INFO(state.wInfoText, /GEOMETRY)
  26.          
  27.            ; Determine the new size based on the amount the window grew
  28.          newTextEditXSize = textEditGeometry.scr_xsize + deltaX
  29.          newTextEditYSize = textEditGeometry.scr_ysize + deltaY
  30.  
  31.            ; Resize the text widget accordingly
  32.          WIDGET_CONTROL, state.wInfoText, SCR_XSIZE=newTextEditXSize, $
  33.            SCR_YSIZE=newTextEditYSize
  34.  
  35.          ENDCASE
  36.  
  37.       ENDCASE
  38.  
  39.    WIDGET_CONTROL, SET_UVALUE = state, event.top, /NO_COPY
  40.  
  41. END
  42.  
  43.  
  44. FUNCTION GetInfoText, fileName, WIDTH=width, HEIGHT=height
  45.  
  46.    OPENR, unit, fileName, /GET_LUN, ERROR=error        ;open the file and then
  47.  
  48.      ; If an error occurred when opening the file
  49.    IF error LT 0 THEN $ 
  50.       buttonPushed = DIALOG_MESSAGE(/ERROR, $
  51.                           [!err_string, ' Can not get information from "' + $
  52.                            fileName + '"']) $
  53.       
  54.    ELSE BEGIN
  55.       maxLines = 1000
  56.       lineInc = 250
  57.       infoText = STRARR(MAXLINES)    ;Maximum # of lines
  58.       lineNumber = 0
  59.       lineOfText = '' 
  60.       lineLength  = 0
  61.       longestLength  = 0
  62.        WHILE NOT EOF(unit) DO BEGIN
  63.  
  64.            READF, unit, lineOfText
  65.  
  66.                 lineLength = lineLength > STRLEN(lineOfText)
  67.             
  68.            infoText[lineNumber] = lineOfText
  69.  
  70.            lineNumber = lineNumber + 1
  71.  
  72.                 ;If the maximum number of lines is hit,
  73.                 ;increase the array size by lineInc
  74.                 IF (lineNumber EQ maxLines) THEN BEGIN
  75.                    infoText = [infoText, STRARR(lineInc)]
  76.                    maxLines = maxLines + lineInc
  77.                 ENDIF
  78.  
  79.           ENDWHILE
  80.  
  81.        infoText = infoText[0:(lineNumber-1) > 0]
  82.  
  83.       IF KEYWORD_SET(height) NE 0 THEN $
  84.          height = lineNumber-1
  85.       IF KEYWORD_SET(width) NE 0 THEN $
  86.          width = lineLength
  87.  
  88.        FREE_LUN, unit                ; Free the file unit.
  89.  
  90.       RETURN, infoText
  91.       ENDELSE
  92.  
  93.    RETURN, ""
  94.  
  95. END
  96.  
  97.  
  98. PRO ShowInfo, fileName, TITLE = title, GROUP = group, WIDTH = width, $
  99.         HEIGHT = height, INFOTEXT = infoText, FONT = font, $
  100.                 XOFFSET = xOffset, YOFFSET=yOffset, NO_NEWLINE=noNewLine
  101.  
  102.    IF (NOT(KEYWORD_SET(noNewLine))) THEN $
  103.       noNewLine = 0
  104.    IF (NOT(KEYWORD_SET(infoText))) THEN BEGIN
  105.  
  106.       IF (NOT(KEYWORD_SET(fileName))) THEN BEGIN
  107.          buttonPushed = DIALOG_MESSAGE(/ERROR, $
  108.             'Filename missing in call to the procedure "ShowInfo"')
  109.          RETURN
  110.          ENDIF
  111.  
  112.       IF (NOT(KEYWORD_SET(title))) THEN $
  113.          title = fileName
  114.  
  115.       WIDGET_CONTROL, /HOURGLASS
  116.       
  117.       infoText = GetInfoText(fileName)
  118.  
  119.       textSize = SIZE(infoText)
  120.       IF (textSize[0] EQ 0) THEN $
  121.          RETURN
  122.  
  123.       ENDIF $
  124.    ELSE BEGIN
  125.       IF (NOT(KEYWORD_SET(title))) THEN $
  126.          title = "Info"
  127.       ENDELSE
  128.  
  129.    IF (NOT(KEYWORD_SET(width))) THEN $
  130.       width = 80
  131.    IF (NOT(KEYWORD_SET(height))) THEN $
  132.       height = 30
  133.  
  134.    IF (KEYWORD_SET(xOffset)) AND (KEYWORD_SET(yOffset)) THEN $
  135.       wInfoWindow = WIDGET_BASE(TITLE=title, UVALUE="INFO_WINDOW", $
  136.         /TLB_SIZE_EVENTS, XOFFSET=xOffset, YOFFSET=yOffset) $
  137.    ELSE $
  138.       wInfoWindow = WIDGET_BASE(TITLE=title, UVALUE="INFO_WINDOW", $
  139.         /TLB_SIZE_EVENTS)
  140.    
  141.    IF N_ELEMENTS(font) GT 0 THEN $
  142.           ; Create a text widget with the desired font
  143.       wInfoText = WIDGET_TEXT(wInfoWindow, XSIZE=width, YSIZE=height, $
  144.                       /SCROLL, FONT=font, VALUE=infoText, $
  145.                            NO_NEWLINE=noNewLine, /WRAP) $
  146.    ELSE $
  147.           ; Create a text widget when no font is specified
  148.       wInfoText = WIDGET_TEXT(wInfoWindow, XSIZE=width, YSIZE=height, $
  149.                       /SCROLL, VALUE=infoText, NO_NEWLINE=noNewLine,$
  150.                            /WRAP)
  151.  
  152.    WIDGET_CONTROL, wInfoWindow, /REALIZE            ; Display the Window
  153.  
  154.    WIDGET_CONTROL, wInfoWindow, TLB_GET_SIZE=windowSize
  155.  
  156.    state = { $
  157.              wInfoWindow : wInfoWindow, $
  158.              wInfoText : wInfoText, $
  159.              windowSize : windowSize $
  160.            }
  161.  
  162.    WIDGET_CONTROL, wInfoWindow, SET_UVALUE=state
  163.  
  164.       ; Register it with the widget manager
  165.    Xmanager, "ShowInfo", wInfoWindow, GROUP_LEADER=group, $
  166.            EVENT_HANDLER="ShowInfoEventHndlr", /NO_BLOCK
  167.  
  168. END  ;--------------------- procedure ShowInfo ----------------------------
  169.